/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa036.kiss.Entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 *
 * @author tomas
 */
@Entity
@Table(name="VYBAVENI_POKOJE")
public class VybaveniPokoje implements Cloneable, Serializable{
    private String nazev;
    private Double cena;
    private Long id;
    private Kolej kolej;
    private Pokoj pokoj;

    @Column(name="NAZEV")
    public String getNazev() {
        return nazev;
    }

    public void setNazev(String nazev) {
        this.nazev = nazev;
    }

    @Column(name="CENA")
    public Double getCena() {
        return cena;
    }

    public void setCena(Double cena) {
        this.cena = cena;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="ID_POKOJE")
    public Long getId() {
        return id;
    }

    public VybaveniPokoje setId ( final Long id ) {

    if ( id != null ) {

      this.id = new Long ( id.longValue () );
    }

    return this;
  }

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="ID_KOLEJ")
    public Kolej getKolej() {
        return kolej;
    }

    public void setKolej(Kolej kolej) {
        this.kolej = kolej;
    }

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="ID_POKOJ")
    public Pokoj getPokoj() {
        return pokoj;
    }

    public void setPokoj(Pokoj pokoj) {
        this.pokoj = pokoj;
    }

    @Override
    public String toString() {
        return "VybaveniPokoje{" + "nazev=" + nazev + ", cena=" + cena + ", id=" + id + ", kolej=" + kolej + ", pokoj=" + pokoj + '}';
    }
    
     public boolean equals ( final Object rhs ) {

    if ( this == rhs ) return true;

    if ( rhs == null ) return false;

    if ( this.getClass () != rhs.getClass () ) return false;

    VybaveniPokoje c = (VybaveniPokoje) rhs;

    return this.id == null ? c.id == null : this.id.equals ( c.id ) &&
        this.kolej == null ? c.kolej == null : this.kolej.equals ( c.kolej ) &&
        this.cena == null ? c.cena == null : this.cena.equals ( c.cena ) &&
        this.nazev == null ? c.nazev == null : this.nazev.equals ( c.nazev ) &&
        this.pokoj == null ? c.pokoj == null : this.pokoj.equals ( c.pokoj );
  }

  @Override
  public int hashCode () {

    final int[] hashCodes = {
        (this.id == null) ? 0 : this.id.hashCode (),
        (this.kolej == null) ? 0 : this.kolej.hashCode (),
        (this.cena == null) ? 0 : this.cena.hashCode (),
        (this.nazev == null) ? 0 : this.nazev.hashCode (),
        (this.pokoj == null) ? 0 : this.pokoj.hashCode ()
    };

    int hash = 17;
    for ( final int currentHashCode: hashCodes ) {

      hash = hash * 31 + currentHashCode;
    }

    return hash;
  }
   public Object clone () {

    try {

      return ( (VybaveniPokoje) super.clone () ).setId ( this.id );
    } catch ( CloneNotSupportedException ex ) {

      assert false: "CloneNotSupportedException thrown";
      return null;
    }
  }
   public void checkState () {

   final boolean noNazev = this.nazev == null || this.nazev.isEmpty ();
   final boolean noCena = this.cena == null;

    if ( noNazev && noCena )  {

      throw new IllegalStateException ( "Nazev a cena musi byt nastaveny" );
    }
  }
}
